﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Nucleo.Wurfl;


namespace System.Web
{
	public static class RequestExtensions
	{
		public static bool IsMobileDeviceRequest(this HttpRequest request)
		{
			return IsMobileDeviceRequest(new HttpRequestWrapper(request));
		}

		public static bool IsMobileDeviceRequest(this HttpRequestBase request)
		{
			if (WurflDeviceManager.Simulator != null)
			{
				return WurflDeviceManager.Simulator.IsMobileDeviceRequest();
			}

			var device = WurflDeviceManager.GetManager().GetDeviceForRequest(HttpContext.Current.Request);
			return device.GetCapability("is_tablet") == "true" || !string.IsNullOrEmpty(device.GetCapability("mobile_browser"));
		}
	}
}
